/* $Id: LoginPanel.java,v 1.7 2005/06/28 18:29:45 the_paranoid_ Exp $ */
/***************************************************************************
 *                      (C) Copyright 2003 - Marauroa                      *
 ***************************************************************************
 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
package games.mapacman.client;

import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 * Summary description for LoginDialog
 *
 */
public class LoginPanel extends JPanel
{
	// Variables declaration
	private JLabel usernameLabel;
	private JLabel serverLabel;
	private JLabel passwordLabel;
	private JTextField usernameField;
	private JPasswordField passwordField;
	private JComboBox serverField;
	private JButton loginButton;
	// End of variables declaration
	private MaPacman client;



    public LoginPanel(MaPacman client)
	{
		super();
		this.client = client;
		initializeComponent();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always regenerated
	 * by the Windows Form Designer. Otherwise, retrieving design might not work properly.
	 * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
	 * to retrieve your design properly in future, before revising this method.
	 */
	private void initializeComponent()
	{
		usernameLabel = new JLabel();
		serverLabel = new JLabel();
		passwordLabel = new JLabel();
		usernameField = new JTextField();
		passwordField = new JPasswordField();
		serverField = new JComboBox();
		serverField.setEditable(true);
		loginButton = new JButton();
		//
		// usernameLabel
		//
		usernameLabel.setText("Type your username");
		//
		// serverLabel
		//
		serverLabel.setText("Choose your JMaPacman Server");
		//
		// passwordLabel
		//
		passwordLabel.setText("Type your password");
		//
		// serverField
		//
        serverField.addItem("jmapacman.mpc-donkey.de");
		serverField.addItem("localhost");

		//
		// loginButton
		//
		loginButton.setText("Login to Server");
		loginButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				loginButton_actionPerformed(e);
			}

		});
		//
		// contentPane
		//
		this.setLayout(null);
		this.setBorder(BorderFactory.createEtchedBorder());
		
		int x = 80;
		int y = 100;
		
		addComponent(this, serverLabel,   x+10,y+10,220,22);
		addComponent(this, usernameLabel, x+10,y+45,220,20);
		addComponent(this, passwordLabel, x+10,y+70,220,20);
		addComponent(this, serverField,   x+230,y+10,220,22);
		addComponent(this, usernameField, x+230,y+45,220,20);
		addComponent(this, passwordField, x+230,y+70,220,20);

		addComponent(this, loginButton,   x+120,y+120,190,30);
		addComponent(this, new JLabel("Go to http://jmapacman.mpc-donkey.de to create an Account !!"),   x,y+180,500,30);
    }
	

	/** Add Component Without a Layout Manager (Absolute Positioning) */
	private void addComponent(Container container,Component c,int x,int y,int width,int height)
	{
		c.setBounds(x,y,width,height);
		container.add(c);
	}

	private void loginButton_actionPerformed(ActionEvent e)
	{
		this.setVisible(false);
        String username=usernameField.getText();
        String password=new String(passwordField.getPassword());
        String server=(String)serverField.getSelectedItem();

		client.setGameOptions(username,password,server,9923);
		(new Thread(client)).start();
		
		

    }

	public void init() {
		
		
	}
	
	
}
